package com.atguigu.service.impl;

import com.atguigu.dao.DeployServiceModuleDao;
import com.atguigu.dao.impl.DeployServiceModuleDaoImpl;
import com.atguigu.pojo.DeployServiceModule;
import com.atguigu.pojo.Page;
import com.atguigu.service.DeployServiceModuleService;

import java.util.List;

public class DeployServiceModuleServiceImpl implements DeployServiceModuleService {
    DeployServiceModuleDao deployServiceModuleDao=new DeployServiceModuleDaoImpl();
    @Override
    public void addDeployServiceModule(DeployServiceModule deployServiceModule) {
        deployServiceModuleDao.addDeployServiceModule(deployServiceModule);
    }

    @Override
    public void updateDeployServiceModule(DeployServiceModule deployServiceModule) {
        deployServiceModuleDao.updateDeployServiceModule(deployServiceModule);
    }

    @Override
    public void deleteDeployServiceModuleById(String id) {
        deployServiceModuleDao.deleteDeployServiceModuleById(id);
    }

    @Override
    public DeployServiceModule queryDeployServiceModuleById(String id) {
        return deployServiceModuleDao.queryDeployServiceModuleById(id);
    }
    @Override
    public DeployServiceModule queryDeployServiceModuleByLastId(String lastId){
        return deployServiceModuleDao.queryDeployServiceModuleByLastId(lastId);
    }
    @Override
    public List<DeployServiceModule> queryDeployServiceModules() {
        return deployServiceModuleDao.queryDeployServiceModules();
    }

    @Override
    public Page page(Integer pageNo, Integer pageSize) {
        Page<DeployServiceModule> page=new Page<>();
        page.setPagesize(pageSize);
        Integer pageTotalCount=deployServiceModuleDao.queryForPageTotalCount();
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal=pageTotalCount/pageSize;
        if(pageTotalCount % pageSize >0){
            pageTotal++;//总条数,除以一页条数,大于0,页码数+1
        }
        page.setPageTotal(pageTotal);
        System.out.println("pageNo 原来是 is:"+pageNo);
        if(pageNo<1){//防止用户输入量太大
            pageNo=1;
        }else if(pageNo>pageTotal){
            pageNo=pageTotal;
        }
        page.setPageNo(pageNo);//当前页码
        System.out.println("pageNo 现在是 is:"+pageNo);
        System.out.println("pageTotal is:"+pageTotal);
        //要得到的是page的items
        Integer begin=(page.getPageNo()-1)*pageSize;
        List<DeployServiceModule> items=deployServiceModuleDao.queryForPageItems(begin,pageSize);
        page.setItems(items);
        return page;
    }
}
